home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- Caption = "FndFile"
- ClientHeight = 3195
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 4680
- LinkTopic = "FndFile"
- ScaleHeight = 3195
- ScaleWidth = 4680
- StartUpPosition = 3 'Windows Default
- Begin VB.TextBox Text3
- Height = 1815
- Left = 240
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 5
- Text = "FndFile.frx":0000
- Top = 840
- Width = 4215
- End
- Begin VB.TextBox Text2
- Height = 285
- Left = 960
- TabIndex = 2
- Text = "D:\"
- Top = 480
- Width = 2655
- End
- Begin VB.TextBox Text1
- Height = 285
- Left = 960
- TabIndex = 1
- Text = "*.*"
- Top = 120
- Width = 1575
- End
- Begin VB.CommandButton Command1
- Caption = "Command1"
- Height = 375
- Left = 1320
- TabIndex = 0
- Top = 2760
- Width = 1575
- End
- Begin VB.Label Label2
- Caption = "Directory:"
- Height = 255
- Left = 120
- TabIndex = 4
- Top = 480
- Width = 735
- End
- Begin VB.Label Label1
- Caption = "File:"
- Height = 255
- Left = 240
- TabIndex = 3
- Top = 120
- Width = 615
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Public Function FindFile(ByVal FileName As String, ByVal Path As String) As String
- Dim hFile As Long, ts As String, WFD As WIN32_FIND_DATA
- Dim result As Long, sAttempt As String, szPath As String
- Dim sPath As String
- szPath = GetRDP(Path) & "*.*" & Chr$(0)
- 'Note: Inline function here
- '----Starts----
- Dim szPath2 As String, szFilename As String
- Dim dwBufferLen As Long, szBuffer As String, lpFilePart As String
- 'Set variables
- szPath2 = Path & Chr$(0)
- szFilename = FileName & Chr$(0)
- szBuffer = String$(MAX_PATH, 0)
- dwBufferLen = Len(szBuffer)
- 'Ask windows if it can find a file matching the filename you gave it.
- result = SearchPath(szPath2, szFilename, vbNullString, dwBufferLen, szBuffer, lpFilePart)
- '----Ends----
- If result Then
- FindFile = StripNull(szBuffer)
- Exit Function
- End If
- 'Start asking windows for files.
- hFile = FindFirstFile(szPath, WFD)
- ts = StripNull(WFD.cFileName)
- Debug.Print ts; Len(ts)
- Text3.Text = Text3.Text & ts & vbCrLf
- 'If WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then
- ' 'Hey look, we've got a directory!
- ' If Not (ts = "." Or ts = "..") Then
- ' 'Don't look for hidden or system directories
- ' If Not (WFD.dwFileAttributes And (FILE_ATTRIBUTE_HIDDEN Or FILE_ATTRIBUTE_SYSTEM)) Then
- ' 'Search directory recursively
- ' sAttempt = FindFile(FileName, GetRDP(Path) & ts)
- ' If sAttempt <> "" Then
- ' FindFile = sAttempt
- ' Exit Do
- ' End If
- ' End If
- ' End If
- 'End If
- WFD.cFileName = ""
- result = FindNextFile(hFile, WFD)
- Loop Until result = 0
- FindClose hFile
- End Function
- Public Function StripNull(ByVal WhatStr As String) As String
- If InStr(WhatStr, Chr$(0)) > 0 Then
- StripNull = Left$(WhatStr, InStr(WhatStr, Chr$(0)) - 1)
- Else
- StripNull = WhatStr
- End If
- End Function
- Public Function GetRDP(ByVal sPath As String) As String
- 'Adds a backslash on the end of a path, if required.
- If sPath = "" Then Exit Function
- If Right$(sPath, 1) = "\" Then GetRDP = sPath: Exit Function
- GetRDP = sPath & "\"
- End Function
- Private Sub Command1_Click()
- Dim t3 As String
- t3 FindFile(Text1, Text2)
- End Sub
-